//
//  TTHomeViewCell.swift
//  TTWeibo
//
//  Created by 陶宏路 on 16/7/23.
//  Copyright © 2016年 陶路路. All rights reserved.
//

import UIKit
import SnapKit
class TTHomeViewCell: UITableViewCell {
    
    private var headView = TTHeadView()
    private var centerView = TTCenterView()
    private var tobarView = TTToBarView()
    private var otherView = TTOtherView()
    
    var OtherViewconstraint:Constraint?
    
    var ttHomeModel:TTHomeCellModel?{
        
        didSet{
            tobarView.ttcellHomeModel = ttHomeModel
            headView.homeCellModel = ttHomeModel
            centerView.tthomeModel = ttHomeModel
//            print(ttHomeModel?.cellModel?.pic_urls)
            self.OtherViewconstraint?.uninstall()
            
            if ttHomeModel?.cellModel?.retweeted_status == nil{
            
                tobarView.snp_updateConstraints(closure: { (make) -> Void in
                    
                    self.OtherViewconstraint =  make.top.equalTo(centerView.snp_bottom).constraint
                })
                
                otherView.hidden = true
                
            }else{
                
                otherView.tthomeModel = ttHomeModel
                
                tobarView.snp_updateConstraints(closure: { (make) -> Void in
                    
                    self.OtherViewconstraint =  make.top.equalTo(otherView.snp_bottom).constraint
                    
                    otherView.hidden = false
                })
            }
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        
        super.init(style:style , reuseIdentifier: reuseIdentifier)
        
        setUpUI()
        setUpLayout()
    }
    
    
    func setUpUI(){
        
        contentView.addSubview(headView)
        contentView.addSubview(centerView)
        contentView.addSubview(tobarView)
        contentView.addSubview(otherView)
    }
    
    func setUpLayout(){
        
        headView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(contentView)
            make.trailing.leading.equalTo(contentView)
//            make.height.equalTo(50)
        }
        
       centerView.snp_makeConstraints { (make) -> Void in
        make.top.equalTo(headView.snp_bottom)
        make.leading.trailing.equalTo(contentView)
        
        }
        
        otherView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(centerView.snp_bottom)
            make.trailing.leading.equalTo(contentView)
        }
        
        
        tobarView.snp_makeConstraints { (make) -> Void in
           OtherViewconstraint =  make.top.equalTo(centerView.snp_bottom).constraint
            make.leading.trailing.equalTo(contentView)
            make.height.equalTo(35)
        }
        
        
        
        contentView.snp_makeConstraints { (make) -> Void in
            make.leading.trailing.top.equalTo(self)
            make.bottom.equalTo(tobarView)
        }
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
